<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <title>订单管理</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        /* 添加样式 */
    </style>
</head>
<body>
<h2>订单管理</h2>
<table id="ordersTable">
    <tr>
        <th>订单ID</th>
        <th>书籍ID</th>
        <th>书名</th>
        <th>书籍价格</th>
        <th>购买者姓名</th>
        <th>地址</th>
        <th>手机号</th>
    </tr>
</table>

<script>
    $(document).ready(function() {
        $.ajax({
            url: 'orders',
            method: 'GET',
            dataType: 'json',
            success: function(data) {
                if (data.length > 0) {
                    $.each(data, function(index, order) {
                        $('#ordersTable').append(
                            '<tr>' +
                            '<td>' + order.id + '</td>' +
                            '<td>' + order.bookId + '</td>' +
                            '<td>' + order.bookName + '</td>' +
                            '<td>' + order.bookPrice + '</td>' +
                            '<td>' + order.buyerName + '</td>' +
                            '<td>' + order.address + '</td>' +
                            '<td>' + order.phone + '</td>' +
                            '</tr>'
                        );
                    });
                } else {
                    $('#ordersTable').append('<tr><td colspan="7">没有订单信息</td></tr>');
                }
            },
            error: function() {
                alert('无法获取订单信息');
            }
        });
    });
</script>
</body>
</html>
